<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名 -->
    <li :class="{completed:item.isSelected}" v-for="item in showList" :key="item.id">
      <div class="view">
        <input class="toggle" type="checkbox" v-model="item.isSelected"/>
        <label>{{ item.text}}</label>
        <button class="destroy" @click="delTask(item.id)"></button>
      </div>
    </li>
  </ul>
  
</template>

<script>

import { mapGetters, mapMutations, mapState } from 'vuex'
export default {
  methods: {
    ...mapMutations(["setTaskList"]),
    delTask(id) {
      let newArray = this._.cloneDeep(this.taskList)
      newArray = newArray.filter(item => item.id !== id)
      this.setTaskList(newArray)
    }
  },
  computed: {
    ...mapState(["taskList", "showList"]),
    ...mapGetters(["showList"])
  }
}
</script>
